<?
class ScheduleLookup
{
  function getMeetings() {
    $db = new DB();
    $cities = array();

    $meetings = $db->setQuery("select distinct city, name, location, address1, address2, zip from meetings m 
			     where city != '' group by city, name, location, address1, address2, zip 
			     order by city, location, name");

    while ($meeting = $meetings->fetch_row()) {
	$city = $meeting[0];
	$name = addslashes($meeting[1]);
	$location = $meeting[2];
	$address1 = $meeting[3];
	$address2 = $meeting[4];
	$zip = $meeting[5];

	// scrub location data
        $location_data = "$location, $address1, $address2, $zip"; 
        $location_data = preg_replace("/, ,/",",",$location_data );
        $location_data = preg_replace("/^, /","",$location_data );

	// add location to meeting object -- indexed by city and meeting name
	$cities[ $city ][ $meeting[1] ][ "LOCATION" ] = $location_data;

        $schedules = $db->setQuery("select distinct m.day, m.time, m.codes from meetings m 
                                  left join days d on d.day = m.day left join times t on t.time = m.time where city = '$city'
                                  and name = '$name' group by m.day, m.time, codes order by d.sequence, t.sequence;");

	// add schedule data to object
	while ($schedule = $schedules->fetch_row()) {
          $cities[ $city ][ $meeting[1] ][ $schedule[0] ] = "$schedule[1]\n$schedule[2]";
	}
    }

    return($cities);
  }
  
}


?>
